package com.keshan.service.impl;

import com.keshan.mapper.BloodPressureMapper;
import com.keshan.pojo.BloodPressure;
import com.keshan.pojo.BloodPressureDayAvg;
import com.keshan.pojo.BloodPressureExample;
import com.keshan.pojo.BloodPressureHide;
import com.keshan.utils.DateUtil;
import com.keshan.service.BloodPressureServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author keshan
 * @date 2022/10/21 - 18:52
 */
@Service
public class BloodPressureServicesImpl implements BloodPressureServices {
    @Autowired
    BloodPressureMapper bloodPressureMapper;
    @Override
    public int insertBySelectiveBloodPressure(BloodPressure bloodPressure) {
        return bloodPressureMapper.insertSelective(bloodPressure);
    }


//    @Override
//    public List<BloodPressure> getBloodPressureListByImeiToday(String imei) {
//        BloodPressureExample bloodPressureExample = new BloodPressureExample();
//        BloodPressureExample.Criteria criteria = bloodPressureExample.createCriteria();
//        criteria.andImeiEqualTo(imei);
//        List<Date> dateList = DateUtil.getStartAndEndToday();
//        criteria.andTimeBeginBetween(dateList.get(0),dateList.get(1));
//        List<BloodPressure> bloodPressureList = bloodPressureMapper.selectByExample(bloodPressureExample);
//        return bloodPressureList;
//    }
//
//    @Override
//    public List<BloodPressureHide> getBloodPressureListHideByImei(String imei) {
//        BloodPressureExample bloodPressureExample = new BloodPressureExample();
//        BloodPressureExample.Criteria criteria = bloodPressureExample.createCriteria();
//        criteria.andImeiEqualTo(imei);
//        return bloodPressureMapper.selectHideByExample(bloodPressureExample);
//    }

    @Override
    public List<BloodPressureHide> getBloodPressureListHideByUsernameToday(String username) {
        BloodPressureExample bloodPressureExample = new BloodPressureExample();
        BloodPressureExample.Criteria criteria = bloodPressureExample.createCriteria();
        criteria.andUsernameEqualTo(username);
        List<Date> dateList = DateUtil.getStartAndEndToday();
        criteria.andTimeBeginBetween(dateList.get(0),dateList.get(1));
        return bloodPressureMapper.selectHideByExample(bloodPressureExample);
    }

    @Override
    public List<BloodPressureDayAvg> getbloodpressureListEverydayAvgMonth(String username) {
        List<Date> dateList = DateUtil.getStartAndEndTwoMonth();
        return bloodPressureMapper.selectEverydayAvg(dateList.get(0),dateList.get(1),username);
    }


}
